function ModelCreator(Model) {
  class ExtendModel extends Model {
    constructor(...args) {
      super(...args)
    }

    async model_find_or_create(model, domain, vals) {
      const Model = await this.env.model(model)
      const one = await Model.search_one(domain)
      if (one) {
        return one
      }
      return Model.create(vals)
    }

    async ref_model_find_or_create(model, domain, vals) {
      const rid = await this.model_find_or_create(model, domain, vals)
      return { model, id: rid }
    }

    async ref(xml_id) {
      // for  version < 15:
      // const args = ['xmlid_to_res_model_res_id', xml_id, true]
      // next for odoo version >=15

      const [module, ref_name] = xml_id.split('.')
      const method = 'check_object_reference'
      const args = [module, ref_name, true]

      const [model, res_id] = await this.call_kw(method, args)
      const res2 = { model, id: res_id }
      return res2
    }
  }
  return ExtendModel
}

const AddonsModels = {
  'ir.model.data': {
    ModelCreator
  }
}

export default AddonsModels
